package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class Input_rmb2 extends AppCompatActivity {
    EditText dollarRateEditText, euroRateEditText, wonRateEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_input_rmb2);

        // 初始化 EditText
        dollarRateEditText = findViewById(R.id.dollar_rate);
        euroRateEditText = findViewById(R.id.euro_rate);
        wonRateEditText = findViewById(R.id.won_rate);

        // 如果有之前保存的汇率数据，则显示在 EditText 中
        Intent intent = getIntent();
        if (intent != null) {
            float dollarRate = intent.getFloatExtra("dollar_rate", 0f);
            float euroRate = intent.getFloatExtra("euro_rate", 0f);
            float wonRate = intent.getFloatExtra("won_rate", 0f);

            dollarRateEditText.setText(String.valueOf(dollarRate));
            euroRateEditText.setText(String.valueOf(euroRate));
            wonRateEditText.setText(String.valueOf(wonRate));
        }
    }

    public void onSaveClicked(View view) {
        // 获取用户输入的汇率数据
        float dollarRate = Float.parseFloat(dollarRateEditText.getText().toString());
        float euroRate = Float.parseFloat(euroRateEditText.getText().toString());
        float wonRate = Float.parseFloat(wonRateEditText.getText().toString());

        // 将汇率数据封装到 Intent 中，并返回给调用者
        Intent resultIntent = new Intent();
        resultIntent.putExtra("dollar_rate", dollarRate);
        resultIntent.putExtra("euro_rate", euroRate);
        resultIntent.putExtra("won_rate", wonRate);
        setResult(RESULT_OK, resultIntent);
        finish();
    }
}
